#ifndef SAMPLEFRAME_H
#define SAMPLEFRAME_H

#include <QGraphicsView>

class SampleFrame : public QGraphicsView
{
    Q_OBJECT
public:
    enum MouseAction{NoFocus, DrawingRect, MovingRect};

    explicit SampleFrame(QWidget *parent = 0);
    void setPixmap(const QString &pixmap_path);
    const QMap<QString, QRect> *getRectMap() const;

public slots:
    void loadRectMap(const QString &file_path);
    void saveRectMap(const QString &file_path);

    void clearRects();
    void clear();

protected:
    virtual void mousePressEvent(QMouseEvent *event);
    virtual void mouseMoveEvent(QMouseEvent *event);
    virtual void mouseReleaseEvent(QMouseEvent *event);
    virtual void mouseDoubleClickEvent(QMouseEvent *event);
    const QPoint &realPos(QMouseEvent *event);

    virtual void keyReleaseEvent(QKeyEvent *event);

private:
    void addCurrentRectItem();
    QGraphicsRectItem *getRectContainsPoint(const QPoint &event_pos);

    QPoint offset_point;
    QRect current_rect;
    QGraphicsRectItem *current_rect_item;
    QList<QGraphicsRectItem *> rect_item_list;

    MouseAction mouse_action;

    QGraphicsPixmapItem *pixmap_item;

signals:
    void error(QString);
    void blankAreaDblClicked();
    void blankAreaClicked();
};

#endif // SAMPLEFRAME_H
